package engineUtil;

import org.lwjgl.Sys;

/*
 * Written as a java interpretation of the class 
 * clock on page 322 of game engine programming by
 */
public class Clock {

	private boolean isPaused;
	
	private long timeCycles;
	
	private double timeScale;
	
	private static double cyclesPerSecond;
	
public Clock()
{
	
	double startTimeSeconds=0.0;
	
	setTimeCycles(secondsToCycles(startTimeSeconds));
	setTimeScale(1.0);
	setPaused(false);
	
	
}//end clock


public static void init()
{
	cyclesPerSecond=Sys.getTime();


}//


public static long secondsToCycles(double timeSeconds)
{

	return (long)(timeSeconds*cyclesPerSecond);

}
//

public double cyclesToSeconds(long timeCycles)
{

	return (double)timeCycles/cyclesPerSecond;
	
}
//


public boolean isPaused() {
	return isPaused;
}


public void setPaused(boolean isPaused) {
	this.isPaused = isPaused;
}


public long getTimeCycles() {
	return timeCycles;
}


public void setTimeCycles(long timeCycles) {
	this.timeCycles = timeCycles;
}


public double getTimeScale() {
	return timeScale;
}


public void setTimeScale(double timeScale) {
	this.timeScale = timeScale;
}

public long calcDeletaSeconds(Clock other)
{

	long dt = timeCycles -other.timeCycles;
	return dt;
	
	
}//end


public void update(double realSeconds)
{
	
	if(!isPaused)
	{
		long dt=secondsToCycles(realSeconds*timeScale);
		timeCycles += dt;
	}
		
}//end update


public void singleStep()
{

	if (isPaused)
	{
	long dt= secondsToCycles(timeScale);
	timeCycles += dt;
	}//
	
}//end 


}
